<template>
  <div class="home_container">
    <el-container>
      <!--头部-->
      <el-header>
        <div class="left">
            <div class="log-bg"></div>
            <span>电商后台管理系统</span>
        </div>
        <div class="buttons">
          <el-tag @click="fullScreen"><span><i class="el-icon-rank"></i>全屏显示</span></el-tag>
          <el-button type="info" @click="logOut">退出</el-button>
        </div>
      </el-header>
      <!--页面主体区域-->
      <el-container>
        <!--侧边栏-->
        <el-aside :width="menuCollapse?'64px':'200px'">
          <div class="toggle-button" @click="toggleCollapse">||||</div>
          <el-menu :collapse="menuCollapse" unique-opened class="el-menu-vertical-demo" background-color="#333644" text-color="#fff" active-text-color="#46A2F9" style="padding-left:auto;"
                   :collapse-transition="false" :router="true" :default-active="'/'+this.$route.path.substr(1)">
            <!--一级菜单-->
            <el-submenu :index="item.id+''" v-for="item in menuList" :key="item.id">
              <!--一级菜单模版区-->
              <template slot="title">
                <i :class="iconsObj[item.id]" :style="{margin:menuCollapse?'0':'10px'}"></i>
                <span>{{item.authName}}</span>
              </template>
              <!--二级菜单-->
              <el-menu-item :index="'/'+submenu.path" v-for="submenu in item.children" :key="submenu.id">
                <template slot="title">
                  <i class="el-icon-menu"></i>
                  <span>{{submenu.authName}}</span>
                </template>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <!--右侧内容主体-->
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
  import connector from '../base/interface.js';
    export default {
      data(){
        return{
          /*左侧菜单列表数据*/
          menuList:[],
          iconsObj:{
            '125':'iconfont icon-users',
            '103':'iconfont icon-tijikongjian',
            '101':'iconfont icon-shangpin',
            '102':'iconfont icon-danju',
            '145':'iconfont icon-baobiao'
          },
          /*菜单栏是否折叠*/
          menuCollapse:false,
          /*当前页面是否是全屏的标识*/
          fullScreenFlag:false,
        }
      },
      methods:{
        logOut(){
          /*退出登陆*/
          window.sessionStorage.clear();
          this.$router.push('/login');
        },
        getMenus(){
          /*获取左侧菜单栏数据*/
          connector.getMenus().then(res=>{
              this.menuList=res.data.data;
          });
        },
        toggleCollapse(){
          /*点击折叠菜单面板*/
          this.menuCollapse=!this.menuCollapse;
        },
        fullScreen(){
          /*全屏显示*/
          if(!this.fullScreenFlag){
            var el = document.documentElement,
              rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullscreen;
            if(typeof rfs != "undefined" && rfs) {
              rfs.call(el);
              this.fullScreenFlag=true;
            }
          }else {
            var el= document,
              cfs = el.cancelFullScreen || el.webkitCancelFullScreen || el.mozCancelFullScreen || el.exitFullScreen;
            if (typeof cfs != "undefined" && cfs) {
              cfs.call(el);
              this.fullScreenFlag=false;
            }
          }
        }
      },
      created() {
        this.getMenus();
      }
    }
</script>

<style lang="scss" scoped>
  @import "../assets/css/public.scss";
  .home_container{
  height: 100%;
  .el-container{height:100%}
  .el-header{
    background: rgb(55,60,64);
    @include flexBetween(row);
    padding-left: 0;
    align-items: center;
    color: white;
    font-size: 25px;
    .buttons{
      @include flexBetween(row);
      align-items: center;
      .el-tag{
        margin-right: 15px;border: none;
        background-color: rgba(0,0,0,0.6);
        &:hover{
          background-color: rgb(123, 253, 26);
        }
      }
      span{
        cursor: pointer;
        font-size: 22px;
        i{
          transform: rotate(45deg);
        }
      }
    }
    .left{
      @include flexBetween(row);
      align-items: center;
      span{
        margin-left: 10px;
        font-weight: bold;
      }
    }
    .log-bg{
      @include bgc('../assets/logo.png');
      @include wh(60px);
      display: inline-block;
      border-radius: 50%;
    }
  }
  .el-aside{
    text-align: left;
    background: rgb(51,54,68);
    transition:width .2s;
    .iconfont{
      font-size: 20px;
    }
    .el-menu{
      border-right: none;
    }
    .toggle-button{
      background-color: #495064;
      color: #ccc;
      font-size: 20px;
      text-align: center;
      letter-spacing: 2px;
      cursor: pointer;
    }
  }
  .main{
    background: rgb(234,237,241);
  }
  .el-main{
    background-color: #EAEDF1;
  }
}
</style>
